// ignore_for_file: unused_import

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/pages/index_page.dart';
import 'package:provider/provider.dart';
import 'routes/routes.dart';
import 'utils/G.dart';
import 'package:provider/provider.dart';
import 'providers/product_provider.dart';
import 'providers/user_provider.dart';
import 'providers/cart_provider.dart';
import '/providers/comment_provider.dart';
import '/providers/order_provider.dart';

void main() {
  //使用路由
  Routes.configureRoutes(G.router);

  runApp(
      // 注册多个Provider
      MultiProvider(providers: [
    ChangeNotifierProvider(create: (_) => ProductProvider()),
    ChangeNotifierProvider(create: (_) => UserProvider()),
    ChangeNotifierProvider(create: (_) => CartProvider()),
    ChangeNotifierProvider(create: (_) => OrderProvider()),
    ChangeNotifierProvider(create: (_) => CommentProvider()),
    // 注册更多的 Provider
  ], child: const MyApp()));
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: const Size(750, 1334),
        builder: () => MaterialApp(
              title: 'Flutter Demo',
              theme: ThemeData(
                primarySwatch: Colors.blue,
              ),
              // home: index_page(),
              onGenerateRoute: G.router.generator,
              navigatorKey: G.navigatorKey, // 声明全局导航唯一键，然后才能获取全局构建上下文
              initialRoute: '/',
            ));
  }
}
